package org.example.curriculum_design_6_16.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.curriculum_design_6_16.entity.pojo.Grade;
import org.example.curriculum_design_6_16.service.GradeService;
import org.example.curriculum_design_6_16.mapper.GradeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author 郑凯
* @description 针对表【grade】的数据库操作Service实现
* @createDate 2025-06-16 09:25:48
*/
@Service
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade>
    implements GradeService{

    @Autowired
    private GradeMapper gradeMapper;

    public GradeServiceImpl(GradeMapper gradeMapper) {
        this.gradeMapper = gradeMapper;
    }

    @Override
    @Transactional
    public boolean addGrade(Grade grade) {
        return gradeMapper.insert(grade) > 0;
    }

    @Override
    @Transactional
    public boolean deleteGradeById(Integer id) {
        return gradeMapper.deleteById(id) > 0;
    }

    @Override
    @Transactional
    public boolean updateGrade(Grade grade) {
        return gradeMapper.updateById(grade) > 0;
    }

    @Override
    public Grade getGradeById(String studentId, String courseId) {
        return gradeMapper.selectByStudentAndCourse(studentId, courseId);
    }

    @Override
    public List<Grade> getAllGrades() {
        return gradeMapper.selectList(null);
    }

    @Override
    public List<Grade> getGradesByStudentId(String studentId) {
        return gradeMapper.selectByStudentId(studentId);
    }

    @Override
    public List<Grade> getGradesByCourseId(String courseId) {
        return gradeMapper.selectByCourseId(courseId);
    }

    @Override
    @Transactional
    public boolean deleteGradesByStudentId(String studentId) {
        return gradeMapper.deleteByStudentId(studentId) > 0;
    }

    @Override
    public Double getAverageGradeByCourse(String courseId) {
        return gradeMapper.selectAverageGradeByCourse(courseId);
    }

    @Override
    public boolean existsGradeForStudentAndCourse(String studentId, String courseId) {
        return gradeMapper.existsByStudentAndCourse(studentId, courseId);
    }

    @Override
    @Transactional
    public boolean updateGradeRemark(Integer gradeId, String remark) {
        return gradeMapper.updateRemark(gradeId, remark) > 0;
    }

    @Override
    public List<Grade> getGradesByStudentIdEFF(String studentId) {
        return gradeMapper.getScoreEFF(studentId);
    }
}




